package com.ganee.agora;


import com.alibaba.android.arouter.launcher.ARouter;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.model.GlideUrl;
import com.facebook.FacebookSdk;
import com.facebook.appevents.AppEventsLogger;
import com.ganee.agora.manager.MediaLoader;
import com.ganee.agora.utils.ClickCheckUtil;
import com.ganee.baselib.httprequest.base.BaseApplication;
import com.ganee.baselib.httprequest.utils.Utils;
import com.yanzhenjie.album.Album;
import com.yanzhenjie.album.AlbumConfig;

import java.io.InputStream;
import java.util.Locale;

import okhttp3.OkHttpClient;

/**
 * @author : EricCui
 * date   : 2019-12-28 13:20
 * desc   :
 */
public class MyApp extends BaseApplication {
    @Override
    public void onCreate() {
        super.onCreate();
        FacebookSdk.sdkInitialize(getApplicationContext());
        AppEventsLogger.activateApp(MyApp.this);
        if (Utils.isAppDebug()){
            ARouter.openDebug();
            ARouter.openLog();
        }
        ARouter.init(this);
        //Glide 图片加载
//        Glide.get(this).register(GlideUrl.class, InputStream.class, new OkHttpUrlLoader.Factory(new OkHttpClient()));

        Album.initialize(AlbumConfig
                        .newBuilder(this)
                        .setAlbumLoader(new MediaLoader())
                        .setLocale(Locale.ENGLISH)
                        .build());

        //监听生命周期
        registerActivityLifecycleCallbacks(new ClickCheckUtil().getLifecycleCallbacks());
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
        ARouter.getInstance().destroy();
    }
}
